package com.dexter.year2023.charpter4_stack.level1;

import java.util.Stack;

/**
 * 用Java提供的Stack，使用方法.push() .empty() .peek() .pop()
 *
 * @author Dexter
 */
public class Demo1Stack {
    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        System.out.println("栈顶元素为：" + stack.peek());
        while (!stack.empty()) {
            System.out.println("此时栈顶元素为：" + stack.peek());
            // 出栈并显示
            System.out.println("出栈元素为：" + stack.pop());

        }
    }
}
